package hashUtil;

/**
 * @Author: sun
 * @Description:
 * @Data: create in 15:20 2018/12/17
 * @Modfied by:
 */

/**
 * Created by xd on 2016/5/15.
 */
public class BBoxPrefix {
    public long prefix;
    public int length;

    public BBoxPrefix(long prefix, int length) {
        this.prefix = prefix;
        this.length = length;
    }

    /**
     * attach 1 behind parentPrefix
     * @return
     */
    public BBoxPrefix attachOne(){
        long bit = 0x8000000000000000L >>> length;
        BBoxPrefix result = new BBoxPrefix(prefix | bit,length + 1);
        return result;
    }

    /**
     * attach 0 behind parentPrefix
     * 这个方法还是要有的，因为需要更改前缀的位数，并且需要new 一个新的出来，不然将会和父前缀引用同一个照成污染
     * @return
     */
    public BBoxPrefix attachZero(){
        //long 属于基本类型，应该不会传引用
        BBoxPrefix result = new BBoxPrefix(prefix,length+1);
        return result;
    }

    @Override
    public String toString() {
    	return length+"  "+Long.toBinaryString(prefix);
    }
}